﻿@{
    RefData d = new RefData();
                 d.RefType = Request["reftype"];
                 d.RefID=Request["refid"];
                 d.RefDesc=Request["desc"];
                 d.Active = Convert.ToInt32(Request["active"]);
                string sql= "SELECT sub.RefTypeDesc as childref, mgr.RefTypeDesc as parentref, val.* FROM ReferenceData val INNER JOIN ReferenceType sub ON sub.RefTypeCode = val.RefType  LEFT JOIN ReferenceType mgr ON mgr.RefTypeCode = val.ParentRefType where val.RefType = @0 and upper(val.RefId) like upper(@1) and Upper(val.RefDesc) like upper(@2) and val.RefType = sub.RefTypeCode and val.Active = @3";
                object[] param = new object[4];
                param[0] = Request["reftype"];
                param[1] = '%' + Request["refid"] + '%';
                param[2] = '%' + Request["RefDesc"] + '%';
                param[3] = Request["active"];
                var query = DBManager.Query(sql,param);

        var cols = new []{"RefType","RefId", "RefDesc"};
        var grid = new WebGrid(query,canSort:false,columnNames:cols,ajaxUpdateContainerId: "grid");
        var getTotal = grid.TotalRowCount;
        var page = grid.PageIndex;
       
        
}
        
<script>
            //maintain webgrid scroll position
     $(function(){
        $('th a, tfoot a').live('click', function(){
            $(this).attr('href', '#grid-anchor');
        });
    
            if(@getTotal=="0"){
            
                $("#message").html("<p class='message error'>No Reference Data found</p>");
            
            }else{
            
                $("#message").empty();   
            
            }
            
            $("#button2").button().click(function(){
    
                  location.href = "/Maintenance/Index/new";
                });    
         });
</script>

    <a name="grid-anchor"></a>    
    <div id="grid" class="ui-widget"  >     
        <fieldset>
          <legend>Search Results</legend>

            <div id="message" ></div>

        
    @grid.GetHtml(
               tableStyle:"webgrid",
               alternatingRowStyle:"webgrid-alternating-row",
               headerStyle:"ui-widget-header",
               fillEmptyRows:true,
               columns:grid.Columns(
                      

                grid.Column(
                      header:"",
                      format:@<a href="/Maintenance/Index/edit?refType=@item.RefType&refId=@item.RefID&refDesc=@item.RefDesc">Edit</a>),
                    
                 grid.Column(
                       columnName:"parentref",
                        header:"Parent Reference Type"),
        
                 grid.Column(
                       columnName:"childref",
                        header:"Reference Type"),
                    
                       grid.Column(
                        columnName:"RefId",
                        header:"Reference ID"
                      ),
                      grid.Column(
                         columnName:"RefDesc",
                         header:"Desc"
                      ),
                    
                    grid.Column(
                       columnName:"CTCBCode",
                        header:"CTCB Code"),
                    
                       grid.Column(
                        columnName:"CTCBDesc",
                        header:"CTCB Desc"
                      ),
                    grid.Column(
                       columnName:"UBPHCode",
                        header:"UBPH Code"),
                    
                       grid.Column(
                        columnName:"UBPHDesc",
                        header:"UBPH Desc"
                      ),  
                        grid.Column(
                       columnName:"PB3Code",
                        header:"PB3 Code"),
                    
                       grid.Column(
                        columnName:"PB3Desc",
                        header:"PB3 Desc"
                      ),
                        grid.Column(
                       columnName:"PB4Code",
                        header:"PB4 Code"),
                    
                       grid.Column(
                        columnName:"PB4Desc",
                        header:"PB4 Desc"
                      ),
                        
                        grid.Column(
                       columnName:"PB5Code",
                        header:"PB5 Code"),
                    
                       grid.Column(
                        columnName:"PB5Desc",
                        header:"PB5 Desc"
                      ),
                    
                        grid.Column(
                       columnName:"PB6Code",
                        header:"PB6 Code"),
                    
                       grid.Column(
                        columnName:"PB6Desc",
                        header:"PB6 Desc"
                      ),
                    
                        grid.Column(
                       columnName:"PB7Code",
                        header:"PB7 Code"),
                    
                       grid.Column(
                        columnName:"PB7Desc",
                        header:"PB7 Desc"
                      ),
                    
                       grid.Column(
                       columnName:"PB8Code",
                        header:"PB8 Code"),
                    
                       grid.Column(
                        columnName:"PB8Desc",
                        header:"PB8 Desc")
                    )
          
            )

 
        
    </fieldset>
</div> 


    